package scripts;
import bot.ScriptMethods;
import javax.swing.JOptionPane;

public class IdentifyHerbs extends ScriptMethods implements Runnable {

	private int itemToWithdraw;
	private int itemToDeposit;

	public void start() {
		getAccountSettings();
		System.gc();

		Object[] options = {"Guam", "Marrentill", "Tarromin", "Harralander", "Ranarr",
							"Irit", "Avantoe", "Kwuarm", "Cadantine", "Dwarf"};

		String res1 = (String)JOptionPane.showInputDialog(null, "", "Identify Herbs", JOptionPane.PLAIN_MESSAGE, null, options, options[0]);

		if (res1.equals("Guam")) {
			itemToWithdraw = 165;
			itemToDeposit = 444;
		} else if (res1.equals("Marrentill")) {
			itemToWithdraw = 435;
			itemToDeposit = 445;
		} else if (res1.equals("Tarromin")) {
			itemToWithdraw = 436;
			itemToDeposit = 446;
		} else if (res1.equals("Harralander")) {
			itemToWithdraw = 437;
			itemToDeposit = 447;
		} else if (res1.equals("Ranarr")) {
			itemToWithdraw = 438;
			itemToDeposit = 448;
		} else if (res1.equals("Irit")) {
			itemToWithdraw = 439;
			itemToDeposit = 449;
		} else if (res1.equals("Avantoe")) {
			itemToWithdraw = 440;
			itemToDeposit = 450;
		} else if (res1.equals("Kwuarm")) {
			itemToWithdraw = 441;
			itemToDeposit = 451;
		} else if (res1.equals("Cadantine")) {
			itemToWithdraw = 442;
			itemToDeposit = 452;
		} else if (res1.equals("Dwarf")) {
			itemToWithdraw = 443;
			itemToDeposit = 453;
		}

		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
	}

	public void stop() {
		System.gc();
		scriptRunning = false;
		scriptThread = null;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();

				if (invContains(itemToWithdraw)) {
					if (!isSleeping()) {
						useItem(itemToWithdraw);
						wait(random(600, 700));
					}
				} else {
					if (bankOpen()) {
						withdraw(itemToWithdraw, 29);
						wait(random(650, 800));
						depositAll(itemToDeposit);
						wait(random(650, 800));
						closeBank();
						wait(600);
					} else {
						openBank();
						wait(2000);
					}
				}

				wait(random(50, 80));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
	}
}